/**
 * 
 */
package main;

/**
 * property中的column及index的映射
 * @author heantai
 * 2013-6-22 下午4:16:46
 * 
 */
public class ColumnMapping {
	private final static String[] fields="name,type,nullable,default,comment,pk".split(",");

	public final static Integer[] idx;
	
	static{
		String[] strings=PropertyUtil.getProperty("fields_idx").split(",");
		idx=new Integer[strings.length];
		for (int i = 0; i < strings.length; i++) {
			if(!strings[i].isEmpty()){
				idx[i]=new Integer(strings[i])-1;
			}
		}
	}
	
	/**
	 * 根据映射设置column的属性
	 * @param c
	 * @param idx
	 * @param value
	 */
	public static void setProperty(Column c,int idx,String value){
		switch (idx) {
		case 0:
			c.setName(value);
			break;
		case 1:
			c.setType(value);
			break;
		case 2:
			if(!PropertyUtil.getProperty("not_null_symbol").equals(value)){
				c.setNullable(true);
			}
			break;
		case 3:
			c.setDefaultV(value);
			break;
		case 4:
			c.setComment(value);
			break;
		case 5:
			if(PropertyUtil.getProperty("is_pk_symbol").equals(value)){
				c.setPk(true);
			}
			break;
		default:
			break;
		}
	}
}
